﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.Cistern;
using University.Workshop.Presenters.Cistern.Search;

namespace University.Workshop.Presentation.Cistern
{
    /// <summary>
    /// Interaction logic for SearchCistern.xaml
    /// </summary>
    public partial class SearchCistern : Page, ISearchCisternView
    {
        PresenterSearchCistern pSearchCistern;

        public SearchCistern()
        {
            InitializeComponent();
            pSearchCistern = new PresenterSearchCistern(this);
        }

        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "Buscar Cisterna";
        }

        public ICollection<Model.Cistern> CisternFinded
        {
            get
            {
                if (CisternFindeddDgv.ItemsSource == null)
                    new List<Model.Cistern>();
                return (ICollection<Model.Cistern>)CisternFindeddDgv.ItemsSource;
            }
            set
            {
                CisternFindeddDgv.ItemsSource = null;
                CisternFindeddDgv.ItemsSource = value;
            }
        }

        public void NotifyErrorMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Error!!!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }
        public void NotifySystemMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Atencion!!!", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }

        public string StateCistern
        {
            get 
            { 
                return CisternStateDdl.SelectionBoxItem.ToString(); 
            }
        }

        public string PlateCistern
        {
            get
            {
                return PlateTxBx.Text;
            }
            set
            {
                PlateTxBx.Text = value;
            }
        }

        public string PersonLastNamesRelative
        {
            get
            {
                return lastNamesTxBx.Text;
            }
            set
            {
                lastNamesTxBx.Text = value;
            }
        }

        public string PersonNamesRelative
        {
            get
            {
                return NamesTxBx.Text;
            }
            set
            {
                NamesTxBx.Text = value;
            }
        }

        private void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            pSearchCistern.SearchCistern();
        }

        private void ShowCisternBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Cistern.Read.ReadCisternPrincipalData((Model.Cistern)CisternFindeddDgv.SelectedItem));
        }

        private void ModifyCisternBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Cistern.Modify.ModifyCisternPrincipal((Model.Cistern)CisternFindeddDgv.SelectedItem));
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "Buscar Cisterna";
        }

        private void DisableCisternBtn_Click(object sender, RoutedEventArgs e)
        {
            pSearchCistern.DisableCistern();
        }

        private void EnableCisternBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Cistern.Modify.ModifyCisternPrincipal((Model.Cistern)CisternFindeddDgv.SelectedItem));
        }

        public bool NotifyConfirmationMessage(string MessageValue)
        {
            return MessageBox.Show(App.Current.MainWindow,
                MessageValue,
                "Atencion!!!",
                MessageBoxButton.YesNo,
                MessageBoxImage.Information,
                MessageBoxResult.Yes,
                MessageBoxOptions.RightAlign) == MessageBoxResult.Yes;
        }

        public void OpenDisableKardexPopUp(Model.Cistern c)
        {
            if (c != null)
            {
            //    Back1.Visibility = Visibility.Visible;
            //    BackDisable.Visibility = Visibility.Visible;
            //    PersonCiTxt.Content = c.Person.PersonId;
            //    PersonNamesForDisableTxt.Content = c.Person.Names;
            //    PersonLastNamesForDisableTxt.Content = c.Person.LastNames;
            //    CisternCapacityForDisabelLbl.Content = c.Capacity;
            //    CisternLicenseForDisableLbl.Content = c.LicencePlate;
            //    App.Current.MainWindow.Title = "UIInhabilitarCisterna";
            }
        }


        public Model.Cistern CisternSelected
        {
            get { return (Model.Cistern)CisternFindeddDgv.SelectedItem; }
        }

        public void HideDisableCistern()
        {
            //Back1.Visibility = Visibility.Hidden;
            //BackDisable.Visibility = Visibility.Hidden;
            //PersonCiTxt.Content = string.Empty;
            //PersonNamesForDisableTxt.Content = string.Empty;
            //PersonLastNamesForDisableTxt.Content = string.Empty;
            //CisternCapacityForDisabelLbl.Content = string.Empty;
            //CisternLicenseForDisableLbl.Content = string.Empty;
            App.Current.MainWindow.Title = "Buscar Cisterna";
        }
        public void GoToModifyCistern(Model.Cistern cistern)
        {
            this.NavigationService.Navigate(new Presentation.Cistern.Modify.ModifyCisternPrincipal(cistern));
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            pSearchCistern.DisableCistern();
        }


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            pSearchCistern.HideDisableCistern();
        }



    }
}
